package com.lapula.crazyface;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Bitmap;
import android.hardware.Camera.Size;

public class D {
	private static D instance = new D();

	/*
	 * 截取区域的上下左右位置
	 */
	public Integer left, right, top, bottom = null;

	private boolean isRecording = false;

	// 相机尺寸
	private Size imageSize;
	private int sizeSide;

	// 记录中的照片
	private List<Bitmap> recordingPics = new ArrayList<Bitmap>();
	// 转为预览的照片
	private List<Bitmap> previewPics = new ArrayList<Bitmap>();

	private D() {
	}

	public static D I() {
		return instance;
	}

	public Size getImageSize() {
		return imageSize;
	}

	public void setImageSize(Size imageSize) {
		this.imageSize = imageSize;
		sizeSide = imageSize.width < imageSize.height ? imageSize.width : imageSize.height;
	}

	public void clearRecordingPics() {
		clearBitmaps(recordingPics);
	}

	public void clearPreviewPics() {
		clearBitmaps(previewPics);
	}

	private void clearBitmaps(List<Bitmap> list) {
		for (Bitmap b : list) {
			if (!b.isRecycled()) {
				b.recycle();
			}
		}
		list.clear();
	}

	public void recordPic(Bitmap pic) {
		recordingPics.add(pic);
	}

	public List<Bitmap> getRecordingPics() {
		return recordingPics;
	}

	public List<Bitmap> getPreviewPics() {
		return previewPics;
	}

	public boolean isRecording() {
		return isRecording;
	}

	public void setRecording(boolean isRecording) {
		this.isRecording = isRecording;
	}

	// 把录像的图片转到预览图片
	public void previewPics() {
		clearPreviewPics();
		for (Bitmap b : recordingPics) {
			previewPics.add(b);
		}
		recordingPics.clear();
	}

	public int getSizeSide() {
		return sizeSide;
	}
}
